from django.db import models
from django import forms
from django.forms import ModelForm
from django.contrib.auth.models import User


class UserProfile(models.Model):
    user = models.ForeignKey(User, unique=True)
    username = models.CharField(max_length=100)
    password = models.CharField(max_length=100)
    
    item_num = models.IntegerField()
    firstname = models.CharField(max_length=100)
    lastname = models.CharField(max_length=100)
    phone = models.CharField(max_length=100)
    email = models.EmailField(max_length=75)
    authority = models.BooleanField()
    
class AuthorityProfile(models.Model):
    user = models.ForeignKey(User, unique=True)
    address = models.CharField(max_length=100)
    phone = models.CharField(max_length=20)
    name = models.CharField(max_length=100)
    
class ReportForm(forms.Form):
    serial = forms.CharField(max_length=100, widget=forms.TextInput(attrs={'placeholder':'Enter Serial Number','label':'Serial Number'}))
    
class UserItem(models.Model):
    user = models.ForeignKey(User)
    item = models.CharField(max_length=100)
    serial = models.CharField(max_length=100)
    
    
class RegisterForm(ModelForm):
    #passwordagain =  forms.CharField(max_length=100,widget=forms.PasswordInput(render_value=False,attrs={'place':'Re-type password','match':'password','label':'Password'}))
    class Meta:
        model = UserProfile 
        exclude = ('user','item_num','authority') 
        widgets= {'password': forms.PasswordInput(render_value=False,attrs={'place':'Password','require':'True','label':'Password','placeholder':'Password'}),
                  'username':forms.TextInput(attrs={'place':'Choose a username','require':'True','label':'Username','placeholder':'Username'}),
                  'email':forms.TextInput(attrs={'place':'Email address','validate':'email','label':'Email','placeholder':'Email'}),
                  'phone':forms.TextInput(attrs={'place':'Phone','label':'Phone','require':'True','placeholder':'Phone Number'}),
                  'firstname':forms.TextInput(attrs={'place':'First Name','label':'First Name','require':'True','placeholder':'First Name'}),
                  'lastname':forms.TextInput(attrs={'place':'Last Name','label':'Last Name','require':'True','placeholder':'Last Name'})}
        

class LoginForm(forms.Form):
    username = forms.CharField(max_length=100,widget=forms.TextInput(attrs={'placeholder':'Username','require':'True','label':'Username'}))
    password = forms.CharField(widget=forms.PasswordInput(render_value=False,attrs={'placeholder':'Password','require':'True','label':'Password'}),max_length=100)
